/****************************************************************************
**
** Copyright (C) 2009 Alexander Solis.
**
** This file is part of Alejandria
** Alejandria is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Alejandria is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Alejandria.  If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

#ifndef LIBRARY_H
#define LIBRARY_H

#include <QObject>
#include <QSqlTableModel>
#include <QSortFilterProxyModel>

enum Columns {
    Id,
    Title,
    Author,
    Category,
    Status,
    Own,
    Rating,
    Loaned,
    Comments
};

class Library : public QObject
{
	Q_OBJECT
	
public:
	Library();
	~Library();
	
	bool connectToDB();
	QAbstractItemModel *getSqlTableModel();
	
	bool insertData(QString, QString, QString, QString, QString, QString, int, bool, QString);
    bool isIdAvailable(const QString &);
	bool deleteData(int);
	
public slots:
    void filter(const QString &);
    void search(const QString &);

private:

	//Private Methods
	void createDBStructure();
	void createModelStructure(QSqlDatabase *);
		
	//Private Variables
    QSortFilterProxyModel   *proxyModel;
	QSqlTableModel          *model;
};

#endif